#include "DataPointer.h"



//default constructor
DataPointer::DataPointer()
{
	data = NULL;
}
//sets the data to void* passed in.
DataPointer::DataPointer(void* d, unsigned long int size)
{
	data = d;
	length = size;
}

//sets the data to void* passed in.
DataPointer::DataPointer(volatile void* d, unsigned long int size)
{
	data = d;
	length = size;
}

//sets the data to void* passed in
void DataPointer::setData(void* d, unsigned long int size)
{
	data = d;
	length = size;
}

//sets the data to void* passed in
void DataPointer::setData(volatile void* d, unsigned long int size)
{
	data = d;
	length = size;
}


//returns the sizeof data. Depends on compiler 
//assuming it returns number of bytes in data.
unsigned int DataPointer::size()
{
	return length;
}

//gets a byte pointer to the data at index i.
BytePointer DataPointer::getByte(unsigned long int byte)
{
	//printf("\n%d\n\n", (data));
	//printf("\n %s \n\n", data+byte);
	//printf("\n %c \n\n", data+byte);
	//cast to a unsigned char* type to make it easier
	volatile unsigned char* byteReferenced = 
			(volatile unsigned char*) (data 
			+ sizeof(volatile unsigned char)*byte);
	//create the byte pointer now.
	BytePointer b = BytePointer(byteReferenced);
	return b;
}


//simple to use interface for getByte
BytePointer DataPointer::operator[](unsigned long int byte)
{
	return DataPointer::getByte(byte);
}


bool DataPointer::operator==(void* pointer)
{
	if(data == pointer) //these are the same
		return true;
	else
		return false;
}

bool DataPointer::operator==(DataPointer& pointer)
{
	if(data == pointer.data && length == pointer.length)
		return true;
	else 
		return false;
}
